﻿var cookie_name = 'cjcke';
var cookies_name = 'cjdke';
var _theme = "energyblue";
var __dictList = {};
var __g_rqts = 0;

//时间对象的格式化
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "H+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds()
    }

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

//计算两个日期天数差的函数，通用
function DateDiff(sDate1, sDate2) {  //sDate1和sDate2是yyyy-MM-dd格式
    // console.log(sDate1);
    // console.log(sDate2);
    var aDate, oDate1, oDate2, iDays;
    aDate = sDate1.split("-");
    oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为yyyy-MM-dd格式
    console.log(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
    aDate = sDate2.split("-");
    oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
    console.log(oDate2);
    iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
    return iDays;  //返回相差天数
}

//计算两个日期天数差的函数，通用
function DateDiff2(dateStr,dayCount) {  //sDate1和sDate2是yyyy-MM-dd格式
    var tempDate=new Date(dateStr.replace(/-/g,"/"));//把日期字符串转换成日期格式
    console.log(tempDate);
    var resultDate=new Date((tempDate/1000+(86400*dayCount))*1000);//增加n天后的日期
    var resultDateStr;
    if((resultDate.getMonth()+1)>=10&&resultDate.getDate()>=10){
        resultDateStr=resultDate.getFullYear()+"-"+(resultDate.getMonth()+1)+"-"+(resultDate.getDate());//将日期转化为字符串格式
    }else if((resultDate.getMonth()+1)<10&&resultDate.getDate()<10){
        resultDateStr=resultDate.getFullYear()+"-0"+(resultDate.getMonth()+1)+"-0"+(resultDate.getDate());//将日期转化为字符串格式
    }else if((resultDate.getMonth()+1)>=10&&resultDate.getDate()<10){
        resultDateStr=resultDate.getFullYear()+"-"+(resultDate.getMonth()+1)+"-0"+(resultDate.getDate());//将日期转化为字符串格式
    }else if((resultDate.getMonth()+1)<10&&resultDate.getDate()>=10){
        resultDateStr=resultDate.getFullYear()+"-0"+(resultDate.getMonth()+1)+"-"+(resultDate.getDate());//将日期转化为字符串格式
    }
    // console.log(resultDateStr);
    return resultDateStr;
}

String.prototype.urlEncode = function () {
    return window.encodeURIComponent ? encodeURIComponent(this) : escape(this)
};
String.prototype.urlDecode = function () {
    return window.decodeURIComponent ? decodeURIComponent(this) : unescape(this)
};

String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
};


function leftPad(a, b) {
    var len = a.length;
    while (len < b) {
        a = "0" + a;
        len++;
    }
    return a;
};
var isArray = function (obj) {
    return Object.prototype.toString.call(obj) === '[object Array]';
}
var isObject = function (obj) {
    return Object.prototype.toString.call(obj) === '[object Object]';
}
var isNum = function (s) {
    if (s != null && s != "") {
        return !isNaN(s);
    }
    return false;
}

function _getCustomerDate(fs) {
    var __a = new Date();
    return __a.format(fs);
}

function _getCurShortDate() {
    var __a = new Date();
    return __a.format('yyyy-MM-dd');
}

function _getMonthsDate() {
    var __a = new Date();
    return __a.format('yyyyMM');
}

function __getMonthsDate() {
    var __a = new Date();
    return __a.format('yyyy-MM');
}

function _getYearsDate() {
    var __a = new Date();
    return __a.format('yyyy');
}

function _getCurTimeDate() {
    var __a = new Date();
    return __a.format('yyyy-MM-dd HH:mm');
}

function _getCurLongDate() {
    var __a = new Date();
    return __a.format('yyyy-MM-dd HH:mm:ss');
}

function _getCurLongLDate() {
    var __a = new Date();
    return __a.format('yyyy-MM-dd HH:mm:ss:S');
}

function _gettimeid() {
    var __a = new Date();
    return __a.format('yyyyMMddHHmmssS');
}

function isNull(val) {
    return ((typeof (val) == 'undefined') || (val === null));
}

function isNotNull(val) {
    return !((typeof (val) == 'undefined') || (val === null));
}

function isNullOrEmpty(val) {
    return ((typeof (val) == 'undefined') || (val === null) || (val === ''));
}

function isNotNullOrEmpty(val) {
    return !((typeof (val) == 'undefined') || (val === null) || (val === ''));
}

function isEmpty(val) {
    if (val) {
        if ((typeof val == undefined) || (val === null) || (val === '')) {
            return true;
        } else if (val.constructor === Object) {
            if (JSON.stringify(val) == '{}') {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }

    } else {
        return true;
    }
}

function toDecimal(x) {
    var f = parseFloat(x);
    if (isNaN(f)) {
        return false;
    }
    var f = Math.round(x * 100) / 100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + 2) {
        s += '0';
    }
    return s;
}

function getBaseHost() {
    var curWwwPath = window.document.location.href;
    var pos = curWwwPath.lastIndexOf(":");
    var localhostPaht = curWwwPath.substring(0, pos);
    return localhostPaht;
}

function getBaseHostAndPort() {
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPaht = curWwwPath.substring(0, pos);
    return localhostPaht;
}

function getBasePath() {
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPaht = curWwwPath.substring(0, pos);
    return (localhostPaht + "/LIMS4.0/");
}

var gPath = getBasePath();
var AsIndex = "banner";
var gCurDate = new Date();

function doAjaxPost(pUrl, pSuccessFunc, pParams, pAsync) {
    $.ajax({
        type: 'POST',
        url: pUrl,
        data: pParams,
        // contentType: "application/json",
        // datatype: "json",
        success: function (d) {
            if (d) {
                pSuccessFunc(d);
            } else {
                layer.alert('提交出现异常', {icon: 5});
            }
        },
        beforeSend: function () {
            // _stips("&nbsp;&nbsp;请稍后");
        },
        error: function (a) {
            if (a.responseText) {
                layer.alert(a.responseText, {icon: 5});
            } else {
                layer.alert("操作出现错误，请稍后再试。", {icon: 5});
            }
        },
        complete: function () {
            // _htips();
        }
    });
}

var regBox = {
    regEmail: /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/, //邮箱
    regMobile: /^0?1[3|4|5|8][0-9]\d{8}$/, //手机
    regTel: /^0[\d]{2,3}-[\d]{7,8}$/
}

//验证数字
function isNumeric(value) {
    // var reg = /^[0-9]+.?[0-9]*$/;
    // 浮点数
    var reg = /^(-?\d+)(\.\d+)?$/;
    if (reg.test(value)) {
        return true;
    }
    return false;
}

//验证正负数字,正负小数
function isNumAddOrSubtract(value) {
    var reg = /(^[\-0-9][0-9]*(.[0-9]+)?)$/;
    if (reg.test(value)) {
        return true;
    }
    return false;
}

//检查是否为正数
function isUnsignedNumeric(a) {
    var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
    return reg.test(a);
}

//检查是否为整数
function isInteger(a) {
    var reg = /^[0-9]+$/;
    return reg.test(a);
}

//检查是否为正整数
function isUnsignedInteger(a) {
    var reg = /^\d+$/;
    return reg.test(a);
}

//检查是否数字
function isNum(a) {
    var reg = /^d+(.d+)?$/;
    return reg.test(a);
}

//检查是否整数
function isInt(a) {
    var reg = /^-?d+$/;
    return reg.test(a);
}

//检查是否电话或者手机
function isphone(a) {
    var mflag = regBox.regMobile.test(a);
    var tflag = regBox.regTel.test(a);
    if (!(mflag && tflag)) {
        return false;
    }
    return true;
}

//检查是否手机
function iscellphone(a) {
    var mflag = regBox.regMobile.test(a);
    if (!(mflag)) {
        return false;
    }
    return true;
}

//检查是否电话
function isTelphone(a) {
    var tflag = regBox.regTel.test(a);
    if (!(tflag)) {
        return false;
    }
    return true;
}

function isEmail(a) {
    var tflag = regBox.regTel.test(a);
    if (!(tflag)) {
        return false;
    }
    return true;
}

function isValuations(a, b) {
    var tflag = regBox[b].test(a)
    if (!(tflag)) {
        return false;
    }
    return true;
}

//日期中的  月、日 转换为双位数
function formatTen(v) {
    if (parseInt(v) < 10) {
        return "0" + v;
    } else {
        return v;
    }
}

//根据日期和有效天数，得到有效的工作日
function _getWorkDay(dat, itervalByDay) {
    var str = dat.split("-");
    var date = new Date();
    date.setUTCFullYear(str[0], str[1] - 1, str[2]);
    date.setUTCHours(0, 0, 0, 0);
    var millisceonds = date.getTime();
    for (var i = 1; i <= itervalByDay; i++) {
        millisceonds += 24 * 60 * 60 * 1000;
        date.setTime(millisceonds);
        //判断是否工作日
        if (date.getDay() == 0 || date.getDay() == 6) {
            i--;
        } else { //判断是否是节假日
            var arr = _getCueYearHoliday();
            for (k in arr) {
                if (arr[k].value == date.format('yyyy-MM-dd')) {
                    i--;
                    break;
                }
            }
        }
    }
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var rq = year + "-" + formatTen(month) + "-" + formatTen(day);
    return rq;
}

function formatTen(v) {
    if (parseInt(v) < 10) {
        return "0" + v;
    } else {
        return v;
    }
}

function getFileName(url) {
    var filename;
    var pos = url.lastIndexOf("/");
    if (pos == -1) {
        pos = url.lastIndexOf("\\");
    } else {

    }
    filename = url.substr(pos + 1);
    pos = filename.lastIndexOf("\\");
    if (pos > 0) {
        filename = filename.substr(pos + 1);
    }
    // var urlname = url.substring(0,pos);
    return filename;
}


function getEndTime(startTime, hour) {
    var nd = new Date(Date.parse(startTime.replace(/-/g, "/"))); //改为标准格式：2016/04/05 09:29:15 
    nd = nd.valueOf(); //转换为毫秒数
    // nd = nd + day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000;
    nd = nd + hour * 60 * 60 * 1000;
    nd = new Date(nd);
    var y = nd.getFullYear();
    var m = nd.getMonth() + 1;
    var d = nd.getDate();
    var hh = nd.getHours();
    var mm = nd.getMinutes();
    var ss = nd.getSeconds();
    if (m <= 9) m = "0" + m;
    if (d <= 9) d = "0" + d;
    if (hh <= 9) hh = "0" + hh;
    if (mm <= 9) mm = "0" + mm;
    if (ss <= 9) ss = "0" + ss;
    var date = y + "-" + m + "-" + d + " " + hh + ":" + mm + ":" + ss;
    return date;
}

function ch2Unicdoe(str) {
    if (!str) {
        return;
    }
    var unicode = '';
    for (var i = 0; i < str.length; i++) {
        var temp = str.charAt(i);
        if (isChinese(temp)) {
            unicode += '\\u' + temp.charCodeAt(0).toString(16);
        } else {
            unicode += temp;
        }
    }
    return unicode;
}

function isChinese(str) {
    return /[\u4e00-\u9fa5]/.test(str);
}

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

